classdef density
   properties
       size
       M
       R
       Sig
       a
   end
   methods
       function den = density(size,M,sig,a)
          den.size = size;
          den.M = M;
          den.Sig = sig;
          den.a = a;
          randn('state',247776455);
          while(1)
              for i=1:size  
                r = randn(size,1); 
                r = r/norm(r);
                den.R = [den.R r];
              end
                den.R = orth(den.R);
                if rank(den.R)==size
                    break
                end        
          end
          den.Sig = den.R'*den.Sig*den.R;
       end
       
       function den = magnify_density(den,size)
           old_size = den.size;
           den.size = size;
           m = den.M;
           den.M = zeros(size,1); den.M(1:old_size) = m;
           sig = den.Sig;
           den.Sig =eye(size); den.Sig(1:old_size,1:old_size) = sig; 
       end
       
       function z = gen_data(den,n)
             z = mvnrnd(den.M',den.Sig,n);
       end
       
       function z = calc_Pdf(den,v)
            z = 1/(2*pi)^(den.size/2)/sqrt(det(den.Sig))*exp(-1/2*(v-den.M)'/den.Sig*(v-den.M));
       end
       
   end
end